<?php
session_start();
$email = ' ';
$name = ' ';
$web = ' '; 
$com = ' ';
$mobile = ' ';


if(isset($_POST['email']) && $_POST['email'] != ''){
    $email = $_POST['email'];
}
if(isset($_POST['name']) && $_POST['name'] != ''){
    $name = $_POST['name'];
}
if(isset($_POST['comname']) && $_POST['comname'] != ''){
    $web = $_POST['comname'];
}
if(isset($_POST['comments']) && $_POST['comments'] != ''){
    $com = $_POST['comments'];
}
if(isset($_POST['mobile']) && $_POST['mobile'] != ''){
    $mobile = $_POST['mobile'];
}
ini_set('display_errors', 1);




$to  = 'anand.vyas@cyberlinks.in';
$subject = 'Site Visiter.';

### for nest latter
if($_GET['a'] == 'news'){
	$message = sprintf("Subscribe For Newsletter,<br> Email:- %s <br>",$email);
	
	
	//if(mail($to, $subject, $message, $headers)){
	$mailCheck = send_email($to,$subject,$message);
	if($mailCheck){
		echo 'You are successfully registed with us, Thank you';
		exit;
	}else{
		echo 'Sorry! Something is wrong please try again';
		exit;
	}
}
// message
if($_GET['a'] == 'con'){
    
	/** Validate captcha */
	if (!empty($_REQUEST['captcha'])) {
	    if (empty($_SESSION['captcha']) || trim(strtolower($_REQUEST['captcha'])) != $_SESSION['captcha']) {
		echo "Invalid captcha.";
		exit;
	    }
	    //unset($_SESSION['captcha']);
	}else{
	    echo 'Please fill the valid captcha.';
	    exit;
	}
    
	$message = sprintf("Site visiter detail, email address,.<br>Email:- %s <br> Name:- %s <br> Company:- %s<br> Commect:- %s<br> mobile:- %s",$email,$name,$web,$com,$mobile);
	
	//if(mail($to, $subject, $message, $headers)){
	$mailCheck = send_email($to,$subject,$message);
	if($mailCheck){
	    echo 'Your Inquiry was successfully sent! Thank you for contacting us';
	    exit;
			
	}else{
	    echo 'Sorry! Something is wrong please try again';
	    exit;
	}
}


function send_email($to,$subject,$body){
    require("PHPMailer/PHPMailerAutoload.php");
    $mail = new PHPMailer();
    $mail->isSMTP(); // Set mailer to use SMTP
    $mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
    $mail->SMTPAuth = true; // Enable SMTP authentication
    $mail->Username = 'cyberlinkslive@gmail.com'; // SMTP username
    $mail->Password = 'Cyberlinks!@#'; // SMTP password
    $mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
    $mail->From = 'Admin@cyberlinks.co.in';
    $mail->FromName = 'Admin Cyberlinks';
    $mail->addAddress($to); // Add a recipient
    $mail->WordWrap = 50; // Set word wrap to 50 characters
    $mail->isHTML(true); // Set email format to HTML
    $mail->Subject = $subject;
    $mail->Body = $body;
    $mail->AltBody = 'Success';
    return $mail->send();
}

//echo '<pre>';print_r($_SERVER);

// Mail it

?>
